//
//  main.m
//  6NSDictionary
//
//  Created by zhengwei on 2/3/16.
//  Copyright © 2016 zhengwei. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        NSDictionary *dic3 = @{@"1.64":@"beijing",@"1.19":@"tianjin"};
        
        //3 数据遍历和快速枚举:中文
        NSArray *array1 = @[dic3,@"123",@"你好"];
        for (NSString *item in array1) {
            NSLog(@"item=%@",item);

            NSArray *array1 = @[dic3];

        }
        NSLog(@"array1 %@",array1);
        
        
        
//        //声明first 层的字典的key值 的数组
//        NSArray * arrayKey = [[NSArray alloc]initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G", nil];
//        //声明一个字典
//        NSMutableDictionary * mFirstDic = [[NSMutableDictionary alloc] initWithCapacity:[arrayKey count]];
//        //遍历arrayKey
//        for (NSString *p in arrayKey) {
//#pragma mark --- 这个是字典 -数组-数组-字典的嵌套
//            //声明一个空的数组，用于存放字典的value
//            NSMutableArray *mFirstArray = [NSMutableArray array];
//            //2现在我想向mFirstArray中添加一个数组
//            //在声明一个新的数组
//            NSMutableArray * mSecondArray = [NSMutableArray array];
//            //添加到mFirstArray这个数组中
//            [mFirstArray addObject:mSecondArray];
//
//            //2.1现在我想向mFirstArray中添加一个字典
//            //声明一个新的字典
//            NSMutableDictionary * mSecondDic = [[NSMutableDictionary alloc] init];
//            [mSecondArray addObject:mSecondDic];
//
//            //将mFirstArray 和arrayKey（即是p）加入到字典（mFirstDic）中
//            [mFirstDic setObject:mFirstArray forKey:p];
//        }
//        NSLog(@"mFirstDic= %@",mFirstDic);
        
        NSArray * arrayKey = [[NSArray alloc]initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G", nil];
    
        //声明一个空的数组，用于存放字典的value
        NSMutableArray *mFirstArray = [NSMutableArray array];
        for (NSString *item in arrayKey) {
            
            //2现在我想向mFirstArray中添加一个数组
            //在声明一个新的数组
            NSMutableArray * mSecondArray = [NSMutableArray array];
            //添加到mFirstArray这个数组中
            [mFirstArray addObject:mSecondArray];
            
            //2.1现在我想向mFirstArray中添加一个字典
            //声明一个新的字典
            //NSMutableDictionary * mSecondDic = [[NSMutableDictionary alloc] init];
           NSDictionary * mSecondDic = [[NSDictionary alloc]initWithObjectsAndKeys: item,@"apple", nil];
            [mSecondArray addObject:mSecondDic];
            
        }
        NSLog(@"mFirstArray= %@",mFirstArray);


        
        /*
//  1 字典的初始化:key-value 水果－当前价格
        NSDictionary *dic1 = [[NSDictionary alloc]init];
        NSDictionary *dic2 = [[NSDictionary alloc]initWithObjectsAndKeys:@"2.5",@"apple",@"2.2",@"orange", nil];
        NSDictionary *dic3 = @{@"1.64":@"beijing",@"1.19":@"tianjin"};
//        NSLog(@"%@ %@ %@",dic1,dic2,dic3);
//  2 增删改查
//        增：
//        查：key索引 我们都是key寻找value
        NSString *str1 = [dic2 valueForKey:@"apple"];
//        查：查所有key 所有的value
        NSArray *array1 = [dic2 allKeys];
        NSArray *array2 = [dic2 allValues];
//        NSLog(@"%@ %@",array1,array2);
//        查：遍历 快速枚举:value key
        for (int i = 0; i < array1.count; i++) {
            NSString *item = [dic2 valueForKey:[array1 objectAtIndex:i]];
//            NSLog(@"item=%@",item);
        }
        for (NSString *item in dic2) {
//            NSLog(@"item=%@",item);
        }
//        查：字典数组混合使用:顺序
        NSArray *array3 = @[@"abc",@"123"];
        NSDictionary *dic4 = [[NSDictionary alloc]initWithObjectsAndKeys:@"value1",@"keya",@"value2",@"keyb",array3,@"keyc", nil];
        NSLog(@"dic4=%@",dic4);
        for (int i = 0; i < [dic4 allKeys].count; i++) {
            id item = [dic4 valueForKey:[[dic4 allKeys] objectAtIndex:i]];
            NSLog(@"item=%@",item);
        }
        */
        /*
//       增：
        NSMutableDictionary *mdic1 = [[NSMutableDictionary alloc]init];
        [mdic1 setValue:@"3" forKey:@"apple"];
        [mdic1 setValue:@"2.5" forKey:@"banana"];
        
//      改：
        [mdic1 setValue:@"8" forKey:@"apple"];
        NSLog(@"%@",mdic1);
//      删：
        [mdic1 removeObjectForKey:@"apple"];
        NSLog(@"%@",mdic1);
        [mdic1 removeAllObjects];
        NSLog(@"%@",mdic1);
         */
//      中文:key－value
        NSDictionary *dic5 = @{@"北京":@"首都"};
        NSLog(@"%@",dic5);
        NSString *item = [dic5 valueForKey:@"北京"];
        NSLog(@"%@",item);
        
    }
    return 0;
}
